import request from "@/utils/axios/request";

interface Exam {
  name: string
  begin: string
  end: string
  duration: number,
  is_limit_jump?: number
  limit_jump_times?: number
  face_recording?: number
  screen_recording?: number
}
const addExam = (exam: Exam) => {
  return request.post('/exam/addExam', exam)
}

const getExams = (params: {
  id?: string;
  pageNum?: any;
  pageSize?: any;
  name?: any;
}) => {
  return request.get(
    `/exam/getExams?pageNum=${params.pageNum}&pageSize=${params.pageSize
    }&name=${params.name}${params.id ? `&id=${params.id}` : ""}`
  );
}

const updateExam = (exam: Exam) => {
  return request.post('/exam/updateExam', exam)
}

const addExamUser = (data: { examId: string, userIds: Array<number> }) => {
  return request.post('/exam/addExamUser', data)
}

const delExamUsers = (data: { examId: string, userIds: Array<number> }) => {
  return request.post('/exam/delExamUsers', data)
}
const sendEmail = (data: { examId: string, userId: string }) => {
  return request.post("/exam/sendEmail", data);
};

const delExam = (ids: Array<number>) => {
  return request.post('/exam/delExam', ids)
}

const updateConfig = (data: { examId: string, is_limit_jump: number, face_recording: number, limit_jump_times: number, screen_recording: number }) => {
  return request.post('/exam/updateConfig', data)
}

const linkExamPaper = (data: { examId: string, testPaperIds: any }) => {
  return request.post('/exam/linkExamPaper', data)
}


const examApi = {
  addExam,
  getExams,
  updateExam,
  addExamUser,
  delExamUsers,
  sendEmail,
  delExam,
  updateConfig,
  linkExamPaper
};

export default examApi
